package com.ruoyi.web.controller.luck;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.luck.domain.LucMarkActive;
import com.ruoyi.luck.service.ILucMarkActiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * luckdrawController
 *
 * @author ruoyi
 * @date 2023-01-29
 */
@RestController
@RequestMapping("/system/luck")
public class LucMarkActiveController extends BaseController
{
    @Autowired
    private ILucMarkActiveService lucMarkActiveService;

    /**
     * 查询luckdraw列表
     */
    @PreAuthorize("@ss.hasPermi('system:luck:list')")
    @GetMapping("/list")
    public TableDataInfo list(LucMarkActive lucMarkActive)
    {
        startPage();
        List<LucMarkActive> list = lucMarkActiveService.selectLucMarkActiveList(lucMarkActive);
        return getDataTable(list);
    }

    /**
     * 导出luckdraw列表
     */
    @PreAuthorize("@ss.hasPermi('system:luck:export')")
    @Log(title = "luckdraw", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LucMarkActive lucMarkActive)
    {
        List<LucMarkActive> list = lucMarkActiveService.selectLucMarkActiveList(lucMarkActive);
        ExcelUtil<LucMarkActive> util = new ExcelUtil<LucMarkActive>(LucMarkActive.class);
        util.exportExcel(response, list, "luckdraw数据");
    }

    /**
     * 获取luckdraw详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:luck:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lucMarkActiveService.getById(id));
    }

    /**
     * 新增luckdraw
     */
    @PreAuthorize("@ss.hasPermi('system:luck:add')")
    @Log(title = "luckdraw", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LucMarkActive lucMarkActive)
    {
        return toAjax(lucMarkActiveService.save(lucMarkActive));
    }

    /**
     * 修改luckdraw
     */
    @PreAuthorize("@ss.hasPermi('system:luck:edit')")
    @Log(title = "luckdraw", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LucMarkActive lucMarkActive)
    {
        return toAjax(lucMarkActiveService.updateById(lucMarkActive));
    }

    /**
     * 删除luckdraw
     */
    @PreAuthorize("@ss.hasPermi('system:luck:remove')")
    @Log(title = "luckdraw", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lucMarkActiveService.removeBatchByIds(Arrays.asList(ids)));
    }
}
